package com.mxl.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;

/**
 * Fanout 模式
 */
//@Configuration
public class FanoutConfig {
    public static final String QUEUE_NAME_FANOUT = "mxl.fanout";
    public static final String QUEUE_NAME_FANOUT2 = "mxl.fanout2";
    public static final String EXCHANGE_NAME_FANOUT = "mxl.fanout";


    @Bean
    Queue fanOutQueue(){
        return new Queue(QUEUE_NAME_FANOUT, true);
    }

    @Bean
    Queue fanOutQueue2(){
        return new Queue(QUEUE_NAME_FANOUT2, true);
    }

    @Bean
    FanoutExchange fanoutExchange(){
        return new FanoutExchange(EXCHANGE_NAME_FANOUT, true, false);
    }

    @Bean
    Binding bindingFanout(){
        return BindingBuilder.bind(fanOutQueue()).to(fanoutExchange());
    }

    @Bean
    Binding bindingFanout2(){
        return BindingBuilder.bind(fanOutQueue2()).to(fanoutExchange());
    }
}
